package com.mdy.sharp.container.res.ds;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

public class ConnectionHolder implements Connection {
    private Connection realConnection;

    public ConnectionHolder(Connection c) {
        this.realConnection = c;
    }

    public Connection getRealConnection() {
        return this.realConnection;
    }

    public void setRealConnection(Connection realConnection) {
        this.realConnection = realConnection;
    }

    public void clearWarnings() throws SQLException {
        this.realConnection.clearWarnings();
    }

    protected void finalize() throws SQLException {
        // super.finalize();
        if (this.realConnection != null && !this.realConnection.isClosed()) {
            this.realConnection.close();
        }
    }

    public void close() throws SQLException {
    }

    public void commit() throws SQLException {
    }

    public void rollback() throws SQLException {
    }

    public void rollback(Savepoint savepoint) throws SQLException {
    }

    public void setAutoCommit(boolean autoCommit) throws SQLException {
    }

    public Statement createStatement() throws SQLException {
        return this.realConnection.createStatement();
    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
            throws SQLException {
        return this.realConnection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
    }

    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
        return this.realConnection.createStatement(resultSetType, resultSetConcurrency);
    }

    public boolean getAutoCommit() throws SQLException {
        return this.realConnection.getAutoCommit();
    }

    public String getCatalog() throws SQLException {
        return this.realConnection.getCatalog();
    }

    public int getHoldability() throws SQLException {
        return this.realConnection.getHoldability();
    }

    public DatabaseMetaData getMetaData() throws SQLException {
        return this.realConnection.getMetaData();
    }

    public int getTransactionIsolation() throws SQLException {
        return this.realConnection.getTransactionIsolation();
    }

    public Map<String, Class<?>> getTypeMap() throws SQLException {
        return this.realConnection.getTypeMap();
    }

    public SQLWarning getWarnings() throws SQLException {
        return this.realConnection.getWarnings();
    }

    public boolean isClosed() throws SQLException {
        return this.realConnection.isClosed();
    }

    public boolean isReadOnly() throws SQLException {
        return this.realConnection.isReadOnly();
    }

    public String nativeSQL(String sql) throws SQLException {
        return this.realConnection.nativeSQL(sql);
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
            int resultSetHoldability) throws SQLException {
        return this.realConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
    }

    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
        return this.realConnection.prepareCall(sql, resultSetType, resultSetConcurrency);
    }

    public CallableStatement prepareCall(String sql) throws SQLException {
        return this.realConnection.prepareCall(sql);
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
            int resultSetHoldability) throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql, resultSetType, resultSetConcurrency,
                resultSetHoldability);

        return new PreparedStatementHolder(realPs, sql);
    }

    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
            throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql, resultSetType, resultSetConcurrency);

        return new PreparedStatementHolder(realPs, sql);
    }

    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql, autoGeneratedKeys);

        return new PreparedStatementHolder(realPs, sql);
    }

    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql, columnIndexes);

        return new PreparedStatementHolder(realPs, sql);
    }

    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql, columnNames);

        return new PreparedStatementHolder(realPs, sql);
    }

    public PreparedStatement prepareStatement(String sql) throws SQLException {
        PreparedStatement realPs = this.realConnection.prepareStatement(sql);
        return new PreparedStatementHolder(realPs, sql);
    }

    public void releaseSavepoint(Savepoint savepoint) throws SQLException {
        this.realConnection.releaseSavepoint(savepoint);
    }

    public void setCatalog(String catalog) throws SQLException {
        this.realConnection.setCatalog(catalog);
    }

    public void setHoldability(int holdability) throws SQLException {
        this.realConnection.setHoldability(holdability);
    }

    public void setReadOnly(boolean readOnly) throws SQLException {
        this.realConnection.setReadOnly(readOnly);
    }

    public Savepoint setSavepoint() throws SQLException {
        return this.realConnection.setSavepoint();
    }

    public Savepoint setSavepoint(String name) throws SQLException {
        return this.realConnection.setSavepoint(name);
    }

    public void setTransactionIsolation(int level) throws SQLException {
        this.realConnection.setTransactionIsolation(level);
    }

    public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException {
        this.realConnection.setTypeMap(arg0);
    }

    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
        return ((ConnectionHolder) this.realConnection).createArrayOf(typeName, elements);
    }

    public Blob createBlob() throws SQLException {
        return ((ConnectionHolder) this.realConnection).createBlob();
    }

    public Clob createClob() throws SQLException {
        return ((ConnectionHolder) this.realConnection).createClob();
    }

    public NClob createNClob() throws SQLException {
        return this.realConnection.createNClob();
    }

    public SQLXML createSQLXML() throws SQLException {
        return ((ConnectionHolder) this.realConnection).createSQLXML();
    }

    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
        return ((ConnectionHolder) this.realConnection).createStruct(typeName, attributes);
    }

    public Properties getClientInfo() throws SQLException {
        return ((ConnectionHolder) this.realConnection).getClientInfo();
    }

    public String getClientInfo(String name) throws SQLException {
        return ((ConnectionHolder) this.realConnection).getClientInfo(name);
    }

    public boolean isValid(int timeout) throws SQLException {
        return ((ConnectionHolder) this.realConnection).isValid(timeout);
    }

    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return ((ConnectionHolder) this.realConnection).isWrapperFor(iface);
    }

    public void setClientInfo(Properties properties) {
        ((ConnectionHolder) this.realConnection).setClientInfo(properties);
    }

    public void setClientInfo(String name, String value) {
        ((ConnectionHolder) this.realConnection).setClientInfo(name, value);
    }

    public <T> T unwrap(Class<T> iface) throws SQLException {
        return (T) ((ConnectionHolder) this.realConnection).unwrap(iface);
    }

    public int hashCode() {
        // int prime = 31;
        int result = 1;
        return 31 * result + ((this.realConnection == null) ? 0 : this.realConnection.hashCode());
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ConnectionHolder other = (ConnectionHolder) obj;
        if (this.realConnection == null) {
            if (other.realConnection != null)
                return false;
        } else if (!this.realConnection.equals(other.realConnection)) {
            return false;
        }
        return true;
    }

    @Override
    public void setSchema(String schema) throws SQLException {
        this.realConnection.setSchema(schema);
    }

    @Override
    public String getSchema() throws SQLException {
        return this.realConnection.getSchema();
    }

    @Override
    public void abort(Executor executor) throws SQLException {
        this.realConnection.abort(executor);
    }

    @Override
    public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
        this.realConnection.setNetworkTimeout(executor, milliseconds);

    }

    @Override
    public int getNetworkTimeout() throws SQLException {
        return this.realConnection.getNetworkTimeout();
    }
}